{********************************************************}
{                                                        }
{                 Zeos Database Objects                  }
{               DB2 Transaction component                }
{                                                        }
{       Copyright (c) 1999-2001 Sergey Seroukhov         }
{    Copyright (c) 1999-2002 Zeos Development Group      }
{                                                        }
{********************************************************}

unit ZDb2SqlTr;

interface

{$R *.dcr}

uses
  Windows, SysUtils, Classes, Db, ZDirDb2Sql, ZDb2SqlCon, ZTransact, ZSqlExtra,
  ZLibDb2Sql, ZToken, ZSqlTypes;

{$INCLUDE ..\Zeos.inc}

type
  { Transaction Interbase component }
  TZZDb2SqlTransact = class(TZZTransact)
  private
    function GetDatabase: TZZDb2SqlDatabase;
    procedure SetDatabase(Value: TZZDb2SqlDatabase);
    function  GetTransIsolation: TZZDb2SqlTransIsolation;
    procedure SetTransIsolation(const Value: TZZDb2SqlTransIsolation);
  public
    constructor Create(AOwner: TComponent); override;

    function ExecFunc(Func: WideString): WideString; override;

    procedure AddMonitor(Monitor: TZZMonitor); override;
    procedure DeleteMonitor(Monitor: TZZMonitor); override;
  published
    property Database: TZZDb2SqlDatabase read GetDatabase write SetDatabase;
    property TransIsolation: TZZDb2SqlTransIsolation read GetTransIsolation
      write SetTransIsolation;
    property TransactSafe;
  end;

implementation

uses ZDbaseConst, ZDirSql;

{***************** TZZDb2SqlTransact implementation *****************}

{ Class constructor }
constructor TZZDb2SqlTransact.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FHandle := TDirDb2SqlTransact.Create(nil);
  FQuery  := TDirDb2SqlQuery.Create(nil, TDirDb2SqlTransact(FHandle));
  FDatabaseType := dtDb2;
end;

{ Get transaction type }
function TZZDb2SqlTransact.GetTransIsolation: TZZDb2SqlTransIsolation;
begin
  Result := TDirDb2SqlTransact(FHandle).TransIsolation;
end;

{ Set transaction type }
procedure TZZDb2SqlTransact.SetTransIsolation(const Value: TZZDb2SqlTransIsolation);
begin
  if Value <> TDirDb2SqlTransact(FHandle).TransIsolation then
  begin
    Disconnect;
    TDirDb2SqlTransact(FHandle).TransIsolation := Value;
  end;
end;

{ Add monitor into monitor list }
procedure TZZDb2SqlTransact.AddMonitor(Monitor: TZZMonitor);
begin
  ZDirDb2Sql.MonitorList.AddMonitor(Monitor);
end;

{ Delete monitor from monitor list }
procedure TZZDb2SqlTransact.DeleteMonitor(Monitor: TZZMonitor);
begin
  ZDirDb2Sql.MonitorList.DeleteMonitor(Monitor);
end;

{ Get database component }
function TZZDb2SqlTransact.ExecFunc(Func: WideString): WideString;
begin
  if Pos('FROM', UpperCase(Func)) <= 0 then
    Func := Func + ' FROM SYSIBM.SYSDUMMY1';
  Result := inherited ExecFunc(Func);
end;

{ Get database component }
function TZZDb2SqlTransact.GetDatabase: TZZDb2SqlDatabase;
begin
  Result := TZZDb2SqlDatabase(FDatabase);
end;

{ Set database component }
procedure TZZDb2SqlTransact.SetDatabase(Value: TZZDb2SqlDatabase);
begin
  inherited SetDatabase(Value);
end;

end.
